<?php

namespace addons\booking\model;

use think\Model;


class RoomState extends Model
{

    // 表名
    protected $name = 'booking_room_state';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $deleteTime = false;

    //检测房态,没有则新增
    public static function check($store_id = 0,$house_ids = [],$date=''){
        $where['date'] = $date;
        $where['store_id'] = $store_id;
        $where['house_id'] = ['in',$house_ids];
        $all_house_ids = self::where($where)->column('house_id');
        $diff_ids = array_diff($house_ids,$all_house_ids);

        $insertAll = [];
        foreach ($diff_ids as $k=>$v){
            $map = [];
            $map['store_id'] = $store_id;
            $map['house_id'] = $v;
            $map['date'] = $date;
            $map['status'] = "0";
            $map['create_time'] = time();
            $insertAll[] = $map;
        }

        if($insertAll){
            self::insertAll($insertAll);
        }
    }
}
